package socrates.movil;

import android.app.ListActivity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;
import java.util.ArrayList;
import java.util.List;
import socrates.dto.ClaseDTO;
import socrates.dto.HorarioDTO;
import socrates.ws.WSHorario;

public class AsA extends ListActivity {

	private List<HorarioDTO> h = null;
	private int g;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		setContentView(R.layout.notacursos);

		ArrayList<String> HORA = new ArrayList<String>();

		h =
						(new WSHorario("http://www.upcferiaexpoti2011.com/SocratesMobile/Service.svc/Horario/",
						1,
						"20111010",
						"20111016")).obtener_horario();

		g = getIntent().getExtras().getInt("d");

		for (HorarioDTO a : h) {
			if (a.getCodigo_dia() == g) {
				for (ClaseDTO e : a.getObjClase()) {

					HORA.add(e.CursoNombre);

				}
			}
		}

		setListAdapter(new ArrayAdapter<String>(this, R.layout.notacurso,
						HORA));

		registerForContextMenu(getListView());
	}

	@Override
	protected void onListItemClick(ListView l, View v, int p, long id) {
		super.onListItemClick(l, v, p, id);
		Intent i = new Intent("HOA", Uri.EMPTY, this, HoraCurso.class);
		for (HorarioDTO a : h) {
			if (a.getCodigo_dia() == g) {
				ClaseDTO e = a.getObjClase().get(p);
				i.putExtra("o", e);
				startActivity(i);
				Toast.makeText(getApplicationContext(),
								((TextView) v).getText(), Toast.LENGTH_SHORT).show();
				break;
			}
		}
	}
}